package com.example.algorithms.sorting;

public class InsertionSort {
	
	public static void main(String... args){
		int[] input = {10, 49, 1, 2, 5, 100, 78, 3, 11};
		
		sort(input);
		
		for (Integer item : input){
			System.out.print(item + " ");
		}
	}
	
	public static void sort(int[] input){
		int minValue = 0;
		
		if ((input != null) && (input.length > 0)){
			
			for (int x = 0; x < input.length - 1; x++){
				
				for (int y = x + 1; y > 0; y--){
					
					if (input[y] < input[y - 1]){
						minValue = input[y];
						input[y] = input[y - 1];
						input[y - 1] = minValue;
					} else {
						break;
					}
				}
			}
		}
	}
}